public class demo2 {
    //使用中序遍历
    long cur=Long.MIN_VALUE;
    public boolean isValidBST(TreeNode root) {
        if(root==null)return true;
        boolean left=isValidBST(root.left);
        if(!left)return false;
        boolean temp=false;
        if(root.val>cur){
            temp=true;
            cur=root.val;
        }
        boolean right=isValidBST(root.right);
        if(!right)return false;
        return left&&right&&temp;
    }
}
